$(function(){
	info();
})
var productIds = [];
var productQtys = [];
function info(){
	productIds = [];
	productQtys = [];
	var id = sessionStorage.getItem("account_order_id");
	var createTime = sessionStorage.getItem("createTime");
	var arr = {
		hf_s_id: 'WD11',
		hf_srv_id: 'Cv_jcus_order',
		hs_action_id: 'get_detail',
		hs_order_id: id
	}
	getAjaxRequest(arr,function(result){
		var type = '';
		if(result.bs_order_typ == 'Normal'){
			type = 'empty';
		}else if(result.bs_order_typ == 'PRE-ORDER'){
			type = 'Pre-order';
		}else if(result.bs_order_typ == 'CNC'){
			type = 'Click & Collect';
		}
		var htmlList = '';
		$('.time').html(createTime);
		$('.state').html(result.bs_status);
		$('.orderNo').html(result.bs_order_no);
		$('#amount').html(result.bj_total_amount);
		$('#type').html(type);
		var product =  result.bvc_cart_item
		var len = product.length;
		if( len>0 ){
			for ( var i = 0; i<len; i++) {
				productIds[i] = product[i].bj_pdt_id;
				productQtys[i] = product[i].bj_qty;
				htmlList += '<div class="item" data-id="'+product[i].bj_pdt_id+'" data-qty="'+product[i].bj_qty+'">'+
							'<div class="proImg">'+
							'<img src="'+MPJ.apiBase+'/'+product[i].bs_limg_file+'"/>'+
							/*'<span><em>offer</em></span>'+*/
							'</div>'+
							'<div class="mui-media-body">'+
							'<div class="pro-name">'+product[i].bs_brand+'</div>'+
							'<div class="pro-f-name">'+product[i].bs_volume+'</div>'+
							'<div class="price">$'+product[i].bj_price_inuse+'</div>'+
							'<div class="price-num">'+
							'<span>Qty:<em>'+product[i].bj_qty+'</em></span>'+
							'<a href="javascript:void(0)" class="addCar mui-btn orderToCart"  data-id="'+product[i].bj_pdt_id+'" data-qty="'+product[i].bj_qty+'" >'+
							'Add<img src="'+MPJ.base+'/resources/images/icon/main-shopcar.png" />'+
							'</a>'+
							'</div>'+
							'</div>'+
							'</div>';
			}
			$('.horizontal-list').html(htmlList);
			add();
			detail();
		}else{
			$('.horizontal-list').html(no_result);
		}
	})
}

function detail(){
	$('.horizontal-list .item').each(function() {
		console.log(4)
		var $this = $(this);
		$this.on('tap', '.proImg', function () {
			console.log(5)
			var pdt_id = $this.data('id');
			var item_no = $this.data('qty');
			var product_info = {};

			product_info.pdt_id = pdt_id;
			product_info.item_no = item_no;
			sessionStorage.setItem('product_info', JSON.stringify(product_info));
			location.href = MPJ.base + "/pages/product/product-detail.jsp";
		})
	})
}